using System;
using Headsight.BPMN2WF.BPMN.Model;
using Headsight.BPMN2WF.Transformation;
using Headsight.BPMN2WF.Transformation.Transformers.Additions;

namespace Headsight.BPMN2WF.WF.Simplification
{
    /// <summary>
    /// <see cref="IBPMN2WFTransformation"/> implementation responsible
    /// for filling <see cref="IBPMN2WFTransformationContext.BPMNTransformationResults"/>
    /// </summary>
    public class BPMN2WFTransformationResultsCollector : BPMN2WFTransformationDelegateBaseImpl
    {
        public BPMN2WFTransformationResultsCollector(IBPMN2WFTransformation @delegate) : base(@delegate)
        {
        }

        public override BPMNTransformationResult Transform(IBPMN2WFTransformationContext ctx, BPMNFlowNode flowNode)
        {
            var result = Delegate.Transform(ctx, flowNode);

            if (!ctx.BPMNTransformationResults.ContainsKey(flowNode))
            {
                ctx.BPMNTransformationResults[flowNode] = result;
            }

            return result;
        }
    }
}